import qs from 'qs';
export function downloadFile(filePath,fileName) {
  if(!fileName){
    fileName = filePath.substring(filePath.lastIndexOf('/')+1);
  }
  this.axios.post(this.lib.config.host.system + "/common/download", qs.stringify({filePath : filePath,fileName : fileName}),{responseType:'arraybuffer'}).then((res)=>{      
   
    //创建一个blob对象,file的一种
    let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
      if (navigator.appVersion.toString().indexOf('.NET') > 0) {
        window.navigator.msSaveBlob(blob, fileName);
      } else {
        let body = document.body;
        let a = document.createElement('a');
        a.download = fileName;
        a.href = URL.createObjectURL(blob);
        body.appendChild(a);
        a.click();
        body.removeChild(a);
      }    
  //  this.$message({
  //     type: 'info',
  //     message: '下载成功!'
  //   });
 })
}

export default {
  downloadFile
}